<?php
namespace app\index\controller;
use think\Request;
use think\Db;
/**
* 
*/
class Altitude extends \think\Controller
{
	
	public function getAltInfo(){
		$request = Request::instance();
        $lon=$request->post('lon','116');
        $lat=$request->post('lat','39');
        //var_dump($city);
           $url='https://maps.google.cn/maps/api/elevation/json?locations='.$lat.','.$lon.'&key=AIzaSyCbLfKHIBp1w36w3y04cK92v2uYNUuO9OU';
        //   var_dump($url);
        // var_dump($url);
       	 $ch = curl_init();
           $timeout = 5;
           curl_setopt($ch, CURLOPT_URL, $url);
           curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
           curl_setopt($ch,CURLOPT_ENCODING ,'gzip');
           curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
           curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //跳过ssl认证；
           $file_contents = curl_exec($ch);
           //var_dump(curl_error($ch)); 
           curl_close($ch);
           return $file_contents;
           //var_dump($file_contents);
         
        //   $map = [
        //       'eqtname' =>  ['=', $city],
        //       'NEWEST'  =>  ['=', 1]
        //   ];
          
        //   $data = [
        //     'clidescription' => $clidescription,
        //     'clidata' =>  $clidata
        //   ];
        //   $data = json_encode($data);
        //   //var_dump($data);
        //   return $data;
         
      
      //  $url = 'http://wthrcdn.etouch.cn/weather_mini?city=北京';
      //   $html = file_get_contents($url);
      // // echo urldecode($html);
      //   echo gzdecode($html);
     
		 
     }

     public function getaddress(){
      $request = Request::instance();
      $lon=$request->get('lon','116');
      $lat=$request->get('lat','39');
      $url='https://maps.google.cn/maps/api/geocode/json?latlng='.$lat.','.$lon.'&key=AIzaSyCbLfKHIBp1w36w3y04cK92v2uYNUuO9OU';
         var_dump($url);
       $ch = curl_init();
      $timeout = 5;
      curl_setopt($ch, CURLOPT_URL, $url);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
      curl_setopt($ch,CURLOPT_ENCODING ,'gzip');
      curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //跳过ssl认证；
      $file_contents = curl_exec($ch);
      //var_dump(curl_error($ch)); 
      curl_close($ch);
      $file_contents = json_decode($file_contents);
      //var_dump($file_contents->results);
      if($file_contents->status=='OK'){
          $res = $file_contents->results[0];
          $street=$res->address_components[0]->long_name;
          $district = $res ->address_components[1]->long_name;
          $CITY = $res ->address_components[2]->long_name;
          $province = $res ->address_components[3] ->long_name;
          //var_dump($CITY);
      }else{
          echo 'googel key 过期';
      }
     }
}
?>